import { request } from './request'

export interface IAddRoleToUserParams {
  accountId: string | number
  roleType: string
}

export function addRoleToUser(params: IAddRoleToUserParams) {
  return request.put(`/menu/addRoleToUser/${params.accountId}/${params.roleType}`)
}

export function findAllAccountMenu(accountId: string | number) {
  return request.get(`/menu/findAllAccountMenu/${accountId}`)
}
// 当前用户菜单树
export function findCurrentUserMenu() {
  return request.get(`/menu/findCurrentUserMenu`)
}

export function findOrgMenuByOrgId(orgId: string | number) {
  return request.get(`/menu/findOrgMenuByOrgId/${orgId}`)
}

export function resetAllMenu() {
  return request.put('/menu/resetAllMenu')
}

export interface IMenu {
  keyId: number
  name: string
  path: string
  status?: number
  type?: number
  children?: IMenu[]
  icon?: string
}

export type IUpsertOrgMenuParams = {
  id: number
  menuList: IMenu[]
  orgId: number
}

export function upsertOrgMenu(params: IUpsertOrgMenuParams) {
  return request.put('/menu/upsertOrgMenu', params)
}

export type IUpsertRoleMenuParams = {
  id: number
  menuList: IMenu[]
  roleName: string
  roleType: string
}

export function upsertRoleMenu(params: IUpsertRoleMenuParams) {
  return request.put('/menu/upsertRoleMenu', params)
}

export type IUpsertUserMenuParams = {
  accountId: number
  id: number
  menuList: IMenu[]
  roles: string[]
}

export function upsertUserMenu(params: IUpsertUserMenuParams) {
  return request.put('/menu/upsertUserMenu', params)
}
